package com.db.addrbook;

import java.util.*;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class AddrBookDAO {
	private SqlMapClientTemplate template;
	
	public void setTemplate(SqlMapClientTemplate template) {
		this.template = template;
	}

	@SuppressWarnings("unchecked")
	public List<Object> getAddrBookList(Map<String, Integer> inmap){
		List<Object> list = new ArrayList<Object>();
		try {
			list = template.queryForList("getABList", inmap);
		} catch (Exception e) {
			System.out.println("AddrBookDAO.getAddrBookList():"+e.toString());
		}
		return list;
	}
	
	public int getTotalPage(AddrBookVO abvo, int lpp){
		int tp = 0;
		try {
			int count = ((Integer)template.queryForObject("getABCount", abvo)).intValue();
			tp = (int)(count / lpp);
			if(count % lpp > 0){
				tp++;
			}
		} catch (Exception e) {
			System.out.println("AddrBookDAO.getTotalPage():"+e.toString());
		}
		return tp;
	}
	
	public AddrBookVO getAddrBookContent(int addrno){
		AddrBookVO vo = new AddrBookVO();
		try {
			vo = (AddrBookVO) template.queryForObject("getABContent", addrno);
		} catch (Exception e) {
			System.out.println("AddrBookDAO.getAddrBookContent():"+e.toString());
		}
		return vo;
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> getAddrBookFind(Map<String, Object> inmap){
		List<Object> list = new ArrayList<Object>();
		try {
			list = template.queryForList("getABFind", inmap);
		} catch (Exception e) {
			System.out.println("AddrBookDAO.getAddrBookFind():"+e.toString());
		}
		return list;
	}
	
	public void insertAddrBook(AddrBookVO vo){
		try {			
			template.insert("insertAddrBook", vo);
		} catch (Exception e) {
			System.out.println("AddrBookDAO.insertAddrBook():"+e.toString());
		}		
	}
	
	public void updateAddrBook(AddrBookVO vo){
		try {
			template.update("updateAddrBook", vo);
		} catch (Exception e) {
			System.out.println("AddrBookDAO.updateAddrBook():"+e.toString());
		}		
	}
	
	public void deleteAddrBook(int addrno){
		try {
			template.delete("deleteAddrBook", addrno);
		} catch (Exception e) {
			System.out.println("AddrBookDAO.deleteAddrBook():"+e.toString());
		}
	}
}
